class Flat
  attr_reader :name, :rates, :response_code, :error
  
  def initialize(zip_to, weight, options)
    # Just do the whole prcess if there is a options[:service_code]
    # same results same amount of time
    yaml = YAML.load(File.new("#{RAILS_ROOT}/config/shipping_rate.yml"))
    
    flat_shipping_config = yaml['flat_shipping']
    @name = flat_shipping_config['name']
    @order_minimum = flat_shipping_config['order_minimum']
    @rate = flat_shipping_config['rate']
    @order_total = options[:total] || 0
    @rates = get_rates
  end
  
  def get_rates
    rates = []
    if @order_total >= @order_minimum
      rates << {
        :service_code => "Flat_flat_#{@rate}",
        :service_description => 'Flat Rate',
        :charge => @rate,
        :currency_code => 'USD'
      }
      return rates
    else
      @error = "Order must be at least #{@order_minimum}"
      return nil
    end
    
  end
end